﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace SuSPExtension
{
	// Token: 0x0200000C RID: 12
	public class Capture
	{
		// Token: 0x0600007F RID: 127 RVA: 0x00002DC8 File Offset: 0x00000FC8
		public Capture(Action<Rect> capturefinishedcallback)
		{
			this._form = new Form();
			this.FormInitlize();
			this._capture_finished_callback = capturefinishedcallback;
			this._form.MouseDown += this.frmMain_MouseDown;
			this._form.MouseMove += this.frmMain_MouseMove;
			this._form.MouseUp += this.frmMain_MouseUp;
		}

		// Token: 0x06000080 RID: 128 RVA: 0x00002E43 File Offset: 0x00001043
		public void CaptureBegin()
		{
			this._form.Show();
		}

		// Token: 0x06000081 RID: 129 RVA: 0x00002E50 File Offset: 0x00001050
		private Bitmap GetScreenCapture()
		{
			Rectangle srcRect = new Rectangle(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
			Bitmap bitmap = new Bitmap(srcRect.Width, srcRect.Height);
			Graphics graphics = Graphics.FromImage(bitmap);
			graphics.CopyFromScreen(0, 0, 0, 0, srcRect.Size);
			graphics.DrawImage(bitmap, 0, 0, srcRect, GraphicsUnit.Pixel);
			return bitmap;
		}

		// Token: 0x06000082 RID: 130 RVA: 0x00002EC0 File Offset: 0x000010C0
		private void FormInitlize()
		{
			Image image = new Bitmap(this.GetScreenCapture());
			Graphics.FromImage(image).FillRectangle(new SolidBrush(Color.FromArgb(100, 0, 0, 0)), 0, 0, image.Width, image.Height);
			this._form.BackgroundImage = image;
			this._form.WindowState = FormWindowState.Maximized;
			this._form.ShowInTaskbar = false;
			this._form.TopMost = true;
			this._form.FormBorderStyle = FormBorderStyle.None;
		}

		// Token: 0x06000083 RID: 131 RVA: 0x00002F40 File Offset: 0x00001140
		private void frmMain_MouseUp(object sender, MouseEventArgs e)
		{
			if (this._capture_finished_callback != null)
			{
				this._capture_finished_callback(new Rect
				{
					width = this.MouseRect.Width,
					height = this.MouseRect.Height,
					posX = this.MouseRect.X,
					posY = this.MouseRect.Y
				});
			}
			this._form.Capture = false;
			Cursor.Clip = Rectangle.Empty;
			this.MouseIsDown = false;
			this.DrawRectangle();
			this.MouseRect = Rectangle.Empty;
			this._form.Hide();
		}

		// Token: 0x06000084 RID: 132 RVA: 0x00002FE2 File Offset: 0x000011E2
		private void frmMain_MouseMove(object sender, MouseEventArgs e)
		{
			if (this.MouseIsDown)
			{
				this.ResizeToRectangle(e.Location);
			}
		}

		// Token: 0x06000085 RID: 133 RVA: 0x00002FF8 File Offset: 0x000011F8
		private void frmMain_MouseDown(object sender, MouseEventArgs e)
		{
			this.MouseIsDown = true;
			this.DrawStart(e.Location);
		}

		// Token: 0x06000086 RID: 134 RVA: 0x00003010 File Offset: 0x00001210
		private void ResizeToRectangle(Point p)
		{
			this.DrawRectangle();
			this.MouseRect.Width = p.X - this.MouseRect.Left;
			this.MouseRect.Height = p.Y - this.MouseRect.Top;
			this.DrawRectangle();
		}

		// Token: 0x06000087 RID: 135 RVA: 0x00003065 File Offset: 0x00001265
		private void DrawRectangle()
		{
			ControlPaint.DrawReversibleFrame(this._form.RectangleToScreen(this.MouseRect), Color.White, FrameStyle.Dashed);
		}

		// Token: 0x06000088 RID: 136 RVA: 0x00003084 File Offset: 0x00001284
		private void DrawStart(Point StartPoint)
		{
			this._form.Capture = true;
			Cursor.Clip = this._form.RectangleToScreen(new Rectangle(0, 0, this._form.ClientSize.Width, this._form.ClientSize.Height));
			this.MouseRect = new Rectangle(StartPoint.X, StartPoint.Y, 0, 0);
		}

		// Token: 0x0400008F RID: 143
		private Form _form;

		// Token: 0x04000090 RID: 144
		private bool MouseIsDown;

		// Token: 0x04000091 RID: 145
		private Rectangle MouseRect = Rectangle.Empty;

		// Token: 0x04000092 RID: 146
		private Action<Rect> _capture_finished_callback;
	}
}
